//
//  HMNewFeatureCollectionVC.m
//  SinaWeiBo
//
//  Created by WGP on 16/4/12.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "HMNewFeatureCollectionVC.h"
#import "HMNewFeatureCollectionCell.h"

@interface HMNewFeatureCollectionVC ()

@end

@implementation HMNewFeatureCollectionVC

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // Register cell classes
    [self.collectionView registerClass:[HMNewFeatureCollectionCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    
}

+(instancetype)newFeatureCollectionVC
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    HMNewFeatureCollectionVC *vc = [[self alloc] initWithCollectionViewLayout:layout];
    vc.collectionView.bounces = NO;
    vc.collectionView.pagingEnabled = YES;
    vc.collectionView.showsHorizontalScrollIndicator = NO;
    
    return vc;
}


#pragma mark <UICollectionViewDataSource>


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return HMNewFeatureCollectionCellCount;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HMNewFeatureCollectionCell *cell = (HMNewFeatureCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    cell.index = indexPath.row;
    
    return cell;
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger index = (int)scrollView.contentOffset.x/scrollView.bounds.size.width;
    if(index == HMNewFeatureCollectionCellCount-1)
    {
        HMNewFeatureCollectionCell *cell = (HMNewFeatureCollectionCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
        [cell startAnimation];
    }
}


@end
